package com.run_java_test.t.test_code;

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import java.io.File;
import java.io.IOException;

public class DynamicJavaCompiler {

    public static void compileJavaFile(String filePath) throws IOException {
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        File javaFile = new File(filePath);
        int result = compiler.run(null, null, null, javaFile.getPath());
        if (result != 0) {
            throw new IOException("Compilation failed for " + javaFile.getPath());
        }
    }
}
